class Solution {
public:
    void merge(vector<int>& A, int m, vector<int>& B, int n) {
        int pa = m - 1;
        int pb = n - 1;
        int cur = A.size() - 1;
        int tmp = 0;
        while (pa >= 0 || pb >= 0)
        {
            if (pa == -1)
                tmp = B[pb--];
            else if (pb == -1)
                tmp = A[pa--];
            else if (A[pa] > B[pb])
            {
                tmp = A[pa];
                pa--;
            }
            else
            {
                tmp = B[pb];
                pb--;
            }
            A[cur--] = tmp;
        }
    }
};